#ifndef XDEMUX_TASK_H
#define XDEMUX_TASK_H
#include "xdemux.h"
#include "xtools.h"
enum XSYN_TYPE {
  XSYN_NONE = 0,  // 不做同步
  XSYN_VIDEO = 1, // 根据视频同步
  XSYN_AUDIO = 2  // 根据音频同步，不处理视频
};

class XCODEC_API XDemuxTask : public XThread {
public:
	XDemuxTask() = default;
	// 打开解封装，并设置超时时间（默认为1ms）
	bool Open(const std::string& url, int timeout_ms = 1000);
	
	/// @brief CopyVideoPara 拷贝视频参数
	std::shared_ptr<XPara> CopyVideoPara() { return demux_.CopyVideoPara(); }
	
	std::shared_ptr<XPara> CopyAudioPara() { return demux_.CopyAudioPara(); }
	
	void set_syn_type(XSYN_TYPE type) { syn_type_ = type; }
	
	int audio_index() { return demux_.audio_index(); }
	
	int video_index() { return demux_.video_index(); }
	
	void Stop()override;

	bool Seek(long long pos_ms);

protected:
  void Main() override;

private:
  XDemux demux_;
  std::string url_;
  int timeout_ms_ = 0;
  XSYN_TYPE syn_type_ = XSYN_NONE;
};

#endif // XDEMUX_TASK_H
